// ListCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "VaxVoipSample.h"
#include "ListCtrlEx.h"


// CListCtrlEx

IMPLEMENT_DYNAMIC(CListCtrlEx, CListCtrl)

CListCtrlEx::CListCtrlEx()
{

}

CListCtrlEx::~CListCtrlEx()
{
}

BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
END_MESSAGE_MAP()

//GetCurSelItem
int CListCtrlEx::GetCurSelItem()
{
	POSITION posSel;
	posSel = GetFirstSelectedItemPosition();
	return GetNextSelectedItem(posSel);
}
//InsertItemText
void CListCtrlEx::InsertItemRow(int nIndex, LPCTSTR sItemText, LPCTSTR sSubItem1)
{
	LVFINDINFO lvFindInfo;
	lvFindInfo.flags = 0;
	lvFindInfo.psz = sItemText;
	int nIndexFindItem = FindItem(&lvFindInfo);
	
	if(nIndexFindItem != -1)
	{
		CString sMessage;
		sMessage.Format("%s is Already Existed", sItemText);
		MessageBox(sMessage);
		return;
	}

	InsertItem(nIndex, sItemText);
	SetItemText(nIndex, 1, sSubItem1); 

	if(GetCurSelItem() == -1)
		SetItemStateSel(0);
}

void CListCtrlEx::SetItemStateSel(int nIndex)
{
   SetItemState(nIndex, LVIS_SELECTED, LVIS_SELECTED);
}

int CListCtrlEx::FindItemIndex(LPCTSTR sItem)
{
	int nFindItenIndex = -1;
	
	LVFINDINFO lvFindInfo;
	lvFindInfo.flags = 0;
	lvFindInfo.psz = sItem;
	nFindItenIndex = FindItem(&lvFindInfo);

	return nFindItenIndex;
}

